package MeiJuLei;

import java.util.Arrays;

/**
 *枚举类的常用方法
 *   valueof(String):找指定名字的对象
 *   toString：打印对象名，重写了toString方法
 *   values():返回枚举类的对象数组
 */
public class Test1 {
    //枚举类的实例化
    public static void main(String[] args) {
        //获取一个season的对象并实例化
        Season spring=Season.SPRING;
        spring.showInfo();
        Season summer=Season.SUMMER;
        summer.showInfo();
        Season autumn=Season.AUTUMN;
        autumn.showInfo();
        Season winter=Season.WINTER;
        winter.showInfo();
        Season spring1=Season.SPRING;

        //枚举类中的每个枚举都是单例的
        System.out.println(spring.equals(spring1));//true
        Season[] values = Season.values();
        System.out.println(Arrays.toString(values));
        //[SPRING, SUMMER, AUTUMN, WINTER]

        //找指定名字的枚举类对象，找不到会报异常
        Season season = Season.valueOf("WINTER");
        System.out.println(season);//WINTER

    }
}
//枚举类
enum Season implements test{
    //1.当前枚举类的对象，逗号隔开，封号结束
    SPRING("春天","春暖花开"),
    SUMMER("夏天","炎炎夏日"),
    AUTUMN("秋天","秋高气爽"),
    WINTER("冬天","寒风凛冽");

    private final String name;
    private final String desc;
    //私有化构造器
    private Season(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }
    public void showInfo(){
        System.out.println(this.name+":"+this.desc);
    }

    @Override
    public void test() {
        System.out.println(" ");
    }
}
interface test{
    public void test();
        }